package servlet;;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import service.PowerBatteryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/PowerBatterySelect")
public class PowerBatterySelect extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("test/html;charset=utf-8");

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        PowerBatteryService powerBatteryService = context.getBean(PowerBatteryService.class);
        req.getSession().setAttribute("id",req.getParameter("id"));
        req.getSession().setAttribute("powerBattery",powerBatteryService.powerSelect(Integer.parseInt(req.getParameter("id"))));
        resp.sendRedirect("update.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
